/**
 * [OElove Webapp] (C)2010-2099 oelove.com Inc.
 * Email: service@phpcoo.com，phpcoo@qq.com
 * This is not a freeware, use is subject to license terms
 * $ LastTime 2017.02.13 Update by CL $
*/
$(function(){

	//弹出支付窗
	$(document).on("click", "[f='but_pay_lineserv']", function(){
		$_id = $(this).attr("data-id");
		$width = $(this).attr("data-width");
		if (typeof($width) == "undefined") {
			$width = 690;
		}
		$height = $(this).attr("data-height");
		if (typeof($height) == "undefined") {
			$height = 500;
		}
		$_url = _ROOT_PATH+"index.php?m=user&c=lineserv&a=pay&id="+$_id+"&r="+get_rndnum(8);
		oeShadeBox("pop_pay_lineserv", "ajax", $_url, $width, $height);
	});

	//选择支付方式
	$(document).on("click", "[f='sel_lineserv_payment']", function(){
		$("._list_lineserv_pay ul li").removeClass("current");
		$(this).addClass("current");
		$_sdkid = $(this).attr("data-sdkid");
		$_sdkname = $(this).attr("data-sdkname");
		
		$("#sdkid").val($_sdkid);
		$("#sdkname").val($_sdkname);
	});
	
	//提交支付
	$(document).on("click", "[f='but_lineserv_pay_submit']", function(){
		$_sdkid = $("#sdkid").val();
		$_sdkname = $("#sdkname").val();
		if ($_sdkid.length == 0) {
			ToastShow("请选择支付方式");
			return false;
		}
		$_id = $(this).attr("data-id");
		$.ajax({
			type: "POST",
			url: _OE_FILE+"&c=lineserv",
			cache: false,
			data: {
					a:"confirmpay", sdkid:$_sdkid, sdkname:$_sdkname, id:$_id, r:get_rndnum(8)
			},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					window.location.href = _ROOT_PATH+"index.php?c=pay&a=submit&paynum="+$result;
				}
				else {
					$_error = $result;
					if ($_error.length == 0) {
						$_error = "提交失败，请检查";
					}
					ToastShow($_error);
				}
			},
			error: function() {
				ToastShow("系统繁忙，请稍后再试");
			}
		});

	});

	
});
